package com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure.db.mybatis.flex.mapper;

import com.gitee.feizns.quickstart.ding.talk.spring.boot.autoconfigure.db.mybatis.flex.pojo.DdDept;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.update.UpdateChain;
import org.apache.ibatis.annotations.Mapper;

import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;

/**
 * 部门映射器
 * @author feizns
 * @since 2025/3/22
 */
@Mapper
public interface DdDeptMapper extends BaseMapper<DdDept> {

    /**
     * 找到由部门编号如选择
     * @return {@link DdDept }
     */
    static Optional<DdDept> findByDdDeptIdAsOpt(Long deptId) {
        return QueryChain.of(DdDept.class).eq(DdDept::getDeptId, deptId).oneOpt();
    }

    /**
     * 找到由编号如选择
     * @param deptId 部门编号
     * @return {@link Optional }<{@link DdDept }>
     */
    static Optional<DdDept> findByDeptIdAsOpt(Long deptId) {
        return QueryChain.of(DdDept.class).eq(DdDept::getDeptId, deptId).oneOpt();
    }

    /**
     * 删除根据部门编号
     * @param deptId 部门编号
     */
    static void removeByDeptId(Long deptId) {
        UpdateChain.of(DdDept.class).eq(DdDept::getDeptId, deptId).remove();
    }

    /**
     * 找到部门编号列表
     * @return {@link Set }<{@link Long }>
     */
    static Set<Long> findDeptIdList() {
        //noinspection unchecked
        return new LinkedHashSet<>(QueryChain.of(DdDept.class).select(DdDept::getDeptId).objListAs(Long.class));
    }

}
